<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增方案')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">方案名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <input type="hidden"  id="showId" th:value="${showId}">
            <label class="col-sm-3 control-label">方案分类：</label>
            <div class="col-sm-8">
                <select name="categoryId" id="categoryId" class="form-control m-b" th:with="type=${@dwl.getType('biz_goods_category')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">功率代码：</label>
            <div class="col-sm-8">
                <input name="barCode" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">方案价格(KWH/元)：</label>
            <div class="col-sm-8">
                <input name="price" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">方案进价(KWH/元)：</label>
            <div class="col-sm-8">
                <input name="costPrice" class="form-control" type="text" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input name="sort" class="form-control" type="number" required>
            </div>
        </div>

<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">方案图片：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input type="hidden" name="diagram">-->
<!--                <div class="file-loading">-->
<!--                    <input class="form-control file-upload" id="diagram" name="file" type="file">-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">方案图片：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input name="diagram"  type="hidden">-->
<!--                &lt;!&ndash;文件数量&ndash;&gt;-->
<!--                <input name="diagramMaxFileCount" value="5" type="hidden">-->
<!--                &lt;!&ndash;单个文件大小&ndash;&gt;-->
<!--                <input name="diagramMaxFileSize" value="20480" type="hidden">-->
<!--                <div class="file-loading">-->
<!--                    <input id="diagram" class="form-control file-upload-biz" multiple name="file" type="file">-->
<!--                </div>-->
<!--                <span style="font-size: 11px;">请上传流程审批表单的附件，允许上传图片格式、PDF格式的文件，单个文件不可大于20M，最多上传5个附件</span>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">方案详情：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input type="hidden" class="form-control" name="descr">-->
<!--                <div class="summernote" id="descr"></div>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">详情图：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input type="hidden" class="form-control" name="descrDiagram">-->
<!--                <div class="summernote" id="descrDiagram"></div>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">启用状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('enableStatus')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js" />
<script th:src="@{/ruoyi/js/systemcommon.js}"></script>
<script th:inline="javascript">

    var prefix = ctx + "biz/goods"
    $("#form-goods-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-goods-add').serialize());
        }
    }

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })

    $(function() {
        var showId = $("#showId").val();
        console.log("showId:",showId)
        if(showId != ''){
            $('#categoryId').attr('disabled', true);
        }
        $("#categoryId").val(showId);

        $('.summernote').summernote({
            lang: 'zh-CN',
            dialogsInBody: true,
            callbacks: {
                onChange: function(contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function(files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function(result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function(error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });


</script>
</body>
</html>